package com.meta.nd.filter.vo;


import com.meta.nd.annotation.bo.FdDef;
import com.meta.nd.annotation.bo.NdDef;
import lombok.Data;
import org.springframework.util.StringUtils;

@Data
@NdDef(ndName = "filterResultFdNd")
public class ResultFd {
    @FdDef("fdName")
    String fdName;
    @FdDef("fdAlias")
    String fdAlias;
    @FdDef("ndName")
    String ndName;
    @FdDef("orderBy")
    int orderBy;
    @FdDef("serNo")
    int serNo;
    String dataType;
    String expression;

    public ResultFd(){

    }

    public ResultFd (String fdName,String fdAlias,String ndName){
        this.fdName = fdName;
        this.ndName = ndName;
        this.fdAlias = fdAlias;
    }

    public static ResultFd buildExpressResultFd(String expression, String dataType, String fdAlias, String ndName){
        ResultFd resultFd = new ResultFd("",fdAlias,ndName);
        resultFd.setExpression(expression);
        resultFd.setDataType(dataType);
        return resultFd;
    }

    public String getFinalName(){
        return (StringUtils.isEmpty(this.fdAlias)) ? this.fdName : this.fdAlias;
    }

    public boolean isExpression(){
        return !StringUtils.isEmpty(this.expression);
    }
}
